<template>
  <van-popup round v-model="show_sub_add" @close="close_pop">
    <div class="form">
      <div class="title">
        <div class="c_flex" style="padding:10px">新增营业额</div>
      </div>
      <van-form validate-trigger="onSubmit" validate-first @submit="onSubmit">
                <normal_item v-model="user_data.amount"  txt_tip="当日营业额" />
                <time_picker :is_min_date="false" icons="end" v-model="user_data.date" txt_tip="统计日期" />
        <div class="submit_out c_flex">
          <van-button native-type="submit" class="submit">确定</van-button>
        </div>
      </van-form>
    </div>
  </van-popup>
</template>

<script>
  import normal_item from '@/views/user/component/normal_item'
  import time_picker from '@/components/TimePicker/index.vue';
  import {
    ShoperService
  } from '@/api';
  export default {
    name: 'add_money',
    props: {
      show_add: Boolean,
      car_id: String,
    },
    computed: {
      show_sub_add: {
        get() {
          return this.show_add
        },
        set(value) {
          console.log(value);
          if (!value) {
            this.close_pop();
          }
        }
      }
    },
    components: {
      normal_item,time_picker
    },
    mounted() {
      
    },
    data() {
      return {
        regions: [],
        user_data: {
          amount: '',
          date: new Date().toISOString().split('T')[0],
        },
        car_raw: '',
      }
    },
    
    methods: {
      
      onSubmit() {  
        ShoperService.addAmount(this.user_data, this.car_id).then(res => {
          console.log(res)
          this.$EventBus.$emit("update_one")
          this.close_pop();
        });
      },
      close_pop() {
        this.empty();
        this.$emit('update:show_add', false);
      },
      empty() {
        this.user_data = {
          plate: '',
          province_id: '',
        }
        this.car_raw = '';
      }
    },
  }
</script>

<style lang="less" scoped>
  .icon_size {
    width: 30px;
    height: 30px;
    margin-right: 15px;
  }

  .form {
    .title {
      width: 50%;
      border-bottom: 1px solid rgba(153, 153, 153, 1);
      margin: 0 auto 15px;
    }

    width:450px;


    .submit_out {
      margin-top: 40px;
      margin-bottom: 30px;
    }

    .submit {

      width: 360px;
      height: 70px;
      border-radius: 37.84px;
      background-color: rgba(235, 95, 17, 1);
      letter-spacing: 1.8px;
      font-size: 28px;
      color: rgba(255, 255, 255, 1);
    }
  }
</style>